package com.system.arrangement.controller;

import com.system.arrangement.been.Arrangement;
import com.system.arrangement.dto.ArrangementDTO;
import com.system.arrangement.service.ArrangementService;
import com.system.arrangement.vo.ArrangementManageVO;
import com.system.arrangement.vo.ArrangementVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * @author 林
 */
@RestController
@RequestMapping("/arrangement")
public class ArrangementController {
    @Autowired
    private ArrangementService arrangementService;

    @PostMapping("/save")
    public Integer saveHandle(@RequestBody Arrangement arrangement){
        return arrangementService.saveArrangement(arrangement);
    }

    @DeleteMapping("/del/{id}")
    public boolean deleteHandle(@PathVariable("id") int id){
        return arrangementService.removeArrangementById(id);
    }

    @PutMapping("/update")
    public boolean updateHandle(@RequestBody Arrangement arrangement){
        return arrangementService.modifyArrangement(arrangement);
    }

    @GetMapping("/get/{id}")
    public Arrangement getHandle(@PathVariable("id") int id){
        return arrangementService.getArrangementById(id);
    }

    @GetMapping("/get/list")
    public List<Arrangement> listHandle(){
        return arrangementService.listAllArrangements();
    }

    @GetMapping("/get/listByDt/{localDate}")
    public List<Arrangement> listByBt(@PathVariable("localDate") LocalDate localDate){
        return arrangementService.listByDt(localDate);
    }

    @GetMapping("/get/findAllByEmployeeIdAndArrangementDt/{employeeId}/{arrangementDt}")
    public List<Arrangement> findAllByEmployeeIdAndArrangementDt(
            @PathVariable("employeeId") int employeeId,
            @PathVariable("arrangementDt") LocalDate arrangementDt
    ){
        return arrangementService.findAllByEmployeeIdAndArrangementDt(employeeId,arrangementDt);
    }

    @GetMapping("/get/findAllByDepartmentIdAndArrangementDt/{departmentId}/{arrangementDt}")
    public List<ArrangementVO> findAllByDepartmentIdAndArrangementDt(
            @PathVariable("departmentId") int departmentId,
            @PathVariable("arrangementDt") LocalDate arrangementDt
    ) {
        return arrangementService.findAllByDepartmentIdAndArrangementDt(departmentId, arrangementDt);
    }

    @GetMapping("/get/stateByDt/{departmentId}/{arrangementDt}")
    public List<String> stateByDt(
            @PathVariable("departmentId") int departmentId,
            @PathVariable("arrangementDt") LocalDate arrangementDt
    ) {
        return arrangementService.stateByDt(departmentId, arrangementDt);
    }

    @PostMapping("/saveArrangement")
    public Integer saveArrangement(@RequestBody ArrangementDTO arrangementDTO){
        return arrangementService.addNewArrangement(arrangementDTO);
    }

    @GetMapping("/get/findAllArrangementManageVO")
    public List<ArrangementManageVO> findAllArrangementManageVO(){
        return arrangementService.findAllArrangementManageVO();
    }

}
